//
//  ZHNavigationController.m
//  黑马微博-1
//
//  Created by wangzhaohui-Mac on 14-7-3.
//  Copyright (c) 2014年 com.Itheima. All rights reserved.
//

#import "WKNavigationController.h"
#import "UIImage+Extension.h"
#import "UIBarButtonItem+Extension.h"
#import "WKNavigationBar.h"
#import "WKTabBar.h"
@interface WKNavigationController ()
@property (nonatomic, weak) UIScrollView *scrollView;
@end

@implementation WKNavigationController


- (void)viewDidLoad
{
    [super viewDidLoad];
    
//    [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackground"] forBarMetrics:UIBarMetricsDefault];
}



/**
 *  当第一次使用这个类的时候调用1次
 */
+ (void)initialize
{
    //设置UIBarButtonItem的主题
    [self setBarButtonItem];
    
    //设置NavigationBar的主题
    [self setNavigationBar];
    
}


/**
 *  设置NavigationBar的主题
 */
+ (void)setNavigationBar
{
    UINavigationBar *appearance = [UINavigationBar appearance];
    
    //如果不是iOS7就设置导航栏背景图片
    if (!iOS7) {
        [appearance setBackgroundImage:[UIImage imageNamed:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault];
    }
    //设置导航栏标题文字属性
    NSMutableDictionary *textDict = [NSMutableDictionary dictionary];
    textDict[UITextAttributeTextColor] = [UIColor blackColor];
    textDict[UITextAttributeFont] = [UIFont systemFontOfSize:20];
    //清除文字阴影 UIOffsetZero是结构体, 只要包装成NSValue对象, 才能放进字典\数组中
    textDict[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetZero];
    
    [appearance setTitleTextAttributes:textDict];
}

/**
 * 设置UIBarButtonItem的主题
 */
+ (void)setBarButtonItem
{
    // 通过appearance对象能修改整个项目中所有UIBarButtonItem的样式
    UIBarButtonItem *appearance = [UIBarButtonItem appearance];
    
    //设置默认状态下文字属性
    NSMutableDictionary *textDict = [NSMutableDictionary dictionary];
    textDict[UITextAttributeTextColor] = [UIColor orangeColor];
    textDict[UITextAttributeFont] = [UIFont systemFontOfSize:15];
    //清除文字阴影
    textDict[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetZero];
    [appearance setTitleTextAttributes:textDict forState:UIControlStateNormal];
    
    //设置高亮状态下文字属性
    NSMutableDictionary *hlightDict = [NSMutableDictionary dictionaryWithDictionary:textDict];
    hlightDict[UITextAttributeTextColor] = [UIColor purpleColor];
    [appearance setTitleTextAttributes:hlightDict forState:UIControlStateHighlighted];
    
    //设置不可用状态下文字属性
    NSMutableDictionary *disablDict = [NSMutableDictionary dictionaryWithDictionary:textDict];
    disablDict[UITextAttributeTextColor] = [UIColor lightGrayColor];
    [appearance setTitleTextAttributes:disablDict forState:UIControlStateDisabled];
    
    //设置按钮的背景图片
    /**设置背景**/
    // 技巧: 为了让某个按钮的背景消失, 可以设置一张完全透明的背景图片
    [appearance setBackgroundImage:[UIImage imageNamed:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count >0) {
        //隐藏底部导航工具栏
        viewController.hidesBottomBarWhenPushed = YES;
        
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemImageName:@"navigationButtonReturn" highlightImage:@"navigationButtonReturnClick" target:self action:@selector(back)];
//        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemImageName:@"navigationButtonRefresh" highlightImage:@"navigationButtonRefreshClick" target:self action:@selector(more)];
    }
    //调用父类的push方法
    [super pushViewController:viewController animated:YES];
}

- (void)back
{
#warning 这里用的是self, 因为self就是当前正在使用的导航控制器
    [self popViewControllerAnimated:YES];
    
    
}

- (void)more
{
    //回到根控制器
    [self popToRootViewControllerAnimated:YES];

}



@end
